# -*- coding: utf-8 -*-
import logging
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

import global_setting

import uuid

def get_uuid_hex():
    u=uuid.uuid4()
    return u.hex
 

"""
ERROR_DEBUG =0
ERROR_INFO  =1
ERROR_WARNING   =2
ERROR_ERROR =3
ERROR_CRITICAL  =4
"""

class Error(Exception):
    code    =0
    msg =None
    note    =None
    level   =None
    name    =""
    
    def __init__(self,note="empty"):
        Exception.__init__(self)
        self.set_note(note)
        
    def set_note(self,note):
        self.note=note
    def get_note(self):
        return self.note


    def __str__(self):
        return "    -    CODE:%d MSG:%s NOTE:%s \n"%(self.code,self.msg,self.note)
    
    def log(self):
        if(self.level   ==  logging.DEBUG):
            logging.debug(self.__str__())

        if(self.level   ==  logging.INFO):
            logging.info(self.__str__())
            
        if(self.level   ==  logging.WARNING):
            logging.warning(self.__str__())
        
        if(self.level   ==  logging.ERROR):
            logging.error(self.__str__())
        
        if(self.level   ==  logging.CRITICAL):
            logging.critical(self.__str__())

class RequestHandler(webapp.RequestHandler):
    def render_error(self,e):
        e.log()
        template_values =  {
                            "error":e
                            }     
        path =  os.path.join(global_setting.base_dir, 'portal/template/error.html')
        #path =  os.path.join(os.path.dirname(__file__), 'portal/template/error.html')
        #self.response.out.write("path:%s"%path)
        self.response.out.write(template.render(path, template_values))
    
            
def main():
    e=Error()
    print e.__class__       

if __name__ == "__main__":      
    main()
        

    